package com.erick.contacts.adapter;

import java.util.List;
import java.util.Map;

import com.erick.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * @Title: ContactsBaseAdapter.java
 * @Package com.chen.adapter
 * @company:科贸学院
 * @Description: 通讯录列表配器器
 * @author ChenBin
 * @date 2012-9-22 下午1:42:14
 * @version V1.0
 */
public class ContactsBaseAdapter extends BaseAdapter {

	private List<Map<String, Object>> list;
	private LayoutInflater layoutInflater;
	public final int viewKey = 0x7f040009;
	private TextView contactsNameText;

	public ContactsBaseAdapter(Context context, List<Map<String, Object>> list) {
		this.list = list;
		this.layoutInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		if (list != null && list.size() > 0) {
			return list.size();
		} else {
			return 0;
		}
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		Map<String, Object> map = list.get(position);
		System.out.println("------map---" + map);
		if (view == null) {
			view = layoutInflater.inflate(R.layout.contacts_list_item, null);
//			contactsImage = (ImageView) view.findViewById(R.id.contacts_image);  
			contactsNameText = (TextView) view.findViewById(R.id.contacts_name);
		} 

		if (map != null && map.size() > 0) {
			/*if (isAlike(position)) {
				contactsImage.setBackgroundResource(R.drawable.head_common_01);
			} else {
				contactsImage.setBackgroundResource(R.drawable.head_common_02);
			}*/
			contactsNameText.setText(String.valueOf(map.get("name")));
			view.setTag(map);
		}
		return view;
	}

	public boolean isAlike(int position) {
		boolean flag = false;
		if (position % 2 == 0) {
			flag = true;
		}
		return flag;
	}
}
